#
# MudBath Application
#
cmake_minimum_required(VERSION 2.6)

project(OgreApp)

if(WIN32)
	set(CMAKE_MODULE_PATH "${OgreApp_SOURCE_DIR}/CMake;$ENV{OGRE_HOME}/CMake/;${CMAKE_MODULE_PATH};")
	set(OGRE_SAMPLES_INCLUDEPATH
		$ENV{OGRE_HOME}/Samples/include
	)
endif(WIN32)

if(UNIX)
	set(CMAKE_MODULE_PATH "${OgreApp_SOURCE_DIR}/CMake;/usr/local/lib/OGRE/cmake/;${CMAKE_MODULE_PATH}")
	set(OGRE_SAMPLES_INCLUDEPATH
		/usr/local/share/OGRE/samples/Common/include/
	)
endif(UNIX)

if (CMAKE_BUILD_TYPE STREQUAL "")
  # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This screws up
  # differentiation between debug and release builds.
  set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None (CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif ()

#IF(NOT CMAKE_BUILD_TYPE)
#  SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
#      "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
#      FORCE)
#ENDIF(NOT CMAKE_BUILD_TYPE)


set(CMAKE_DEBUG_POSTFIX "_d")

set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/dist")

FIND_PACKAGE(Boost REQUIRED)
FIND_PACKAGE(OGRE REQUIRED)
FIND_PACKAGE(OIS REQUIRED)
FIND_PACKAGE(Bullet REQUIRED)
#FIND_PACKAGE(MYGUI REQUIRED)
FIND_PACKAGE(CEGUI REQUIRED)
FIND_PACKAGE(LUA REQUIRED)
FIND_PACKAGE(SigC REQUIRED)
#FIND_PACKAGE(Gnash REQUIRED)
FIND_PACKAGE(OpenAL REQUIRED)

set(HEADERS)
set(SOURCES ${OgreApp_SOURCE_DIR}/main.cpp)

INCLUDE_DIRECTORIES(
	MudBath
	libs
	libs/BtOgre
	libs/tinyxml
	libs/my-gui/Common
	libs/angelscript
	
	### Gnash
	libs/gnash
	libs/gnash/librender
	libs/gnash/libbase
	libs/gnash/libcore
	libs/gnash/libcore/swf
	libs/gnash/libcore/vm
	libs/gnash/libcore/parser
	libs/gnash/libcore/asobj
	
	${MYGUI_INCLUDE_DIR}
	${CEGUI_INCLUDE_DIRS}
	${Bullet_INCLUDE_DIRS}
	${LUA_INCLUDE_DIR}
	${SIGC_INCLUDE_DIRS}
#	${GNASH_INCLUDE_DIRS}
	${ANGLESCRIPT_INCLUDE_DIR}
	${OPENAL_INCLUDE_DIR}
	${OIS_INCLUDE_DIRS}
	${OGRE_INCLUDE_DIRS}
	${OGRE_SAMPLES_INCLUDEPATH}
)


ADD_SUBDIRECTORY (MudBath)
ADD_SUBDIRECTORY (libs)
ADD_SUBDIRECTORY (Samples)

SET(CMAKE_REQUIRED_LIBRARIES)

#add_definitions(-Wall -Wextra -pedantic -Werror)

SET_TARGET_PROPERTIES(MudBath PROPERTIES COMPILE_FLAGS -fPIC)
SET_TARGET_PROPERTIES(libs PROPERTIES COMPILE_FLAGS -fPIC)
SET_TARGET_PROPERTIES(MudBath PROPERTIES LINK_FLAGS -Wl -shared -fPIC)

SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl -shared -fPIC")

SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fPIC")
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -fPIC")

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fPIC")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -fPIC")

IF(CMAKE_COMPILER_IS_GNUCC)
  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fmessage-length=0")
ENDIF(CMAKE_COMPILER_IS_GNUCC)
IF(CMAKE_COMPILER_IS_GNUCXX)
  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fmessage-length=0")
ENDIF(CMAKE_COMPILER_IS_GNUCXX)



find_package(Doxygen)
if (DOXYGEN_FOUND STREQUAL "YES")
	add_custom_target(doxygen ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
endif (DOXYGEN_FOUND STREQUAL "YES")

link_directories ("/usr/local/lib" "/usr/local/lib/gnash")

add_dependencies(libs MudBath script)
add_executable(OgreApp ${HEADERS} ${SOURCES})
target_link_libraries(OgreApp
	libs MudBath script
	${OGRE_LIBRARIES}
	${OIS_LIBRARIES}
	${LUA_LIBRARY}
	${CEGUI_LIBRARIES}
	-lCEGUIOgreRenderer
	-lCEGUIBase
	-lCEGUILuaScriptModule
	#${MYGUI_LIBRARIES}
	#-lMyGUI.OgrePlatform
	${BULLET_LIBRARIES}
	${SIGC_LIBS}
	
#	${GNASH_LIBS}
#	-lgnashrender
	
	${OPENAL_LIBRARY}
	${Boost_LIBRARIES}
	${CMAKE_REQUIRED_LIBRARIES}
)

